#include "whalewindow.h"

#include <QtDebug>
#include <QCloseEvent>
#include <QSettings>

WhaleWindow::WhaleWindow( QWidget * parent ) : QMainWindow( parent ), mDialogsLocked( false ) {
    // beautify screen
    this->setContentsMargins( 0, 0, 0, 0 );
    layout()->setSpacing( 0 );
    this->layout()->setMargin( 0 );

    // set favicon for all windows
    QPixmap faviconimg( ":/images/favicon.jpg" );
    this->setWindowIcon( QIcon( faviconimg ) );
    this->setWindowTitle( "Social Whale" );

    this->restoreState();
}

// some dialogs don't want other dialogs open
void WhaleWindow::setDialogsLocked( bool locked ) {
    this->mDialogsLocked = locked;
}

bool WhaleWindow::dialogsLocked() {
    return this->mDialogsLocked;
}

void WhaleWindow::closeEvent( QCloseEvent * event ) {
    this->saveState();
    QMainWindow::closeEvent( event );
}

// use QSettings for window state storing
void WhaleWindow::restoreState() {
    QSettings settings;
    QMainWindow::restoreGeometry( settings.value( "wingeometry" ).toByteArray() );
    QMainWindow::restoreState( settings.value( "winstate" ).toByteArray() );
}

void WhaleWindow::saveState() {
    QSettings settings;
    settings.setValue( "wingeometry", QMainWindow::saveGeometry() );
    settings.setValue( "winstate", QMainWindow::saveState() );
}
